Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clones skipped rewrites instead of taking #34311

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

brooksprumo
Copy link
Contributor

@brooksprumo brooksprumo commented Dec 4, 2023

Problem

While debugging a test in #34280, I discovered the issue was due to skipped rewrites getting taken when doing the accounts delta hash calculation. Usually this isn't a problem. But, when we call bank_to_xxx_snapshot_archive(), we call Bank::rehash(), which does another accounts delta hash calculation. Except this second time there are no more skipped rewrites! This means the bank hash in the snapshot is always wrong (when skipping rewrites but also including them in the bank hash).

In #34280 we are solving that by rebuilding the skipped rewrites. Maybe that's not the best solution? We can also fix the problem very simply by cloning the skipped rewrites instead of using take().

Summary of Changes

Clone the skipped rewrites instead of taking them.

Note that the new test will fail without cloning the skipped rewrites.

@brooksprumo brooksprumo self-assigned this Dec 4, 2023
Copy link

codecov bot commented Dec 4, 2023

Codecov Report

Merging #34311 (874b1f7) into master (8fbe033) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #34311   +/-   ##
=======================================
  Coverage    81.9%    81.9%           
=======================================
  Files         819      819           
  Lines      220084   220119   +35     
=======================================
+ Hits       180347   180409   +62     
+ Misses      39737    39710   -27     

@@ -6909,7 +6909,7 @@ impl Bank {
.calculate_accounts_delta_hash_internal(
slot,
ignore,
std::mem::take(&mut self.skipped_rewrites.lock().unwrap()),
self.skipped_rewrites.lock().unwrap().clone(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another option, with no runtime cost, is to pass &RwLock<HashMap...>>.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also use something like the OnceLock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! I originally didn't want to modify calculate_accounts_delta_hash_internal(), which takes the skipped rewrites by value and mutates it.

We can borrow the skipped rewrites and pass a reference into calculate_accounts_delta_hash_internal(). Inside though, we need to only add the rewrites that were not already in the vec of modified accounts in this slot. Currently that iterates the vec of modified accounts and removes any matches in the skipped rewrites.

If we do not modify the skipped rewrites, then I think we'll need to selectively add the skipped rewrites to the vec by searching the vec for each pubkey that's in the skipped rewrites. This feel slow, but I'm not sure if it's faster/slower than the clone.

Wdyt? Or would you like me to get runtime numbers for both versions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh. I forgot we modify it. clone is fine.

@jeffwashington jeffwashington self-requested a review December 4, 2023 17:47
Copy link
Contributor

@jeffwashington jeffwashington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@brooksprumo brooksprumo merged commit efaec08 into solana-labs:master Dec 4, 2023
33 checks passed
@brooksprumo brooksprumo deleted the rewrites/clone branch December 4, 2023 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants